﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;

namespace RBTools.Performances
{
    public static class PerformanceHelper
    {
        public static long Excute(MethodInfo methodInfo, int count)
        {
            if (methodInfo.IsStatic)
            {
                Stopwatch watch = Stopwatch.StartNew();
                watch.Reset();
                watch.Start();

                int i = 0;
                while (i++ < count)
                {
                    methodInfo.Invoke(null, null);
                }

                watch.Stop();
                return watch.ElapsedMilliseconds;
            }
            throw new InvalidOperationException("Could only count the static method's performance!");
        }
    }
}
